// pages/contact/contact.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userProfile: {
      job: '财税经理',
      location: '广州',
      profession: '金融',
      email: '2223269451@qq.com',
      wechat: 'y893178438',
      mobile: '13422031193',
      github: 'https://github.com/MoTec95',
      qq:'2223269451',
    },
    contactInfo: [
      {
        "id": 1,
        "imgUrl": "../../images/contact/about.png",
        "msg": "联系人：",
        "detail": "彭小姐"
      },
      {
        "id": 3,
        "imgUrl": "../../images/contact/handphone.png",
        "msg": "联系电话：",
        "detail": "13422031193"
        //"detail": "13422031193 / 13518803487"
      },
      {
        "id": 4,
        "imgUrl": "../../images/contact/address.png",
        "msg": "总部地址：",
        "detail": "广东省广州市黄埔大道299号"
      },
    ],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('onLoad')
    var that = this
      //更新数据
      that.setData({
        userInfo: app.globalData.userInfo,
        phoneNum: app.globalData.phoneNum,
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title : '一米企业 - 联系我们',
    }
  },
  contactInfoClick:function(e){
    let that = this
    var id = e.currentTarget.id
    console.log(e)
    switch (e.currentTarget.id){
      case "2":
      case "3":
        let phonenum;
        wx.showActionSheet({
          itemList: ['13422031193', '13518803487'],
          success: function (res) {
            if (0 == res.tapIndex){
              phonenum = '13422031193';
            }else{
              phonenum = '13518803487';
            }
            wx.makePhoneCall({
              phoneNumber: phonenum
            })
          },
          fail: function (res) {
            console.log(res.errMsg)
          }
        })
        
      break;
      case "4":
        that.showAddr(23.12044, 113.37727,"广东省广州市黄埔大道299号",'一米企业')
        break;
      case "5":
        that.showAddr(23.12044, 113.37727, '广东省广州市黄埔大道299号','一米企业')
        break;
      default:
    }
  },
  showAddr(latitude, longitude, address, name){
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      address: address,
      name: name,
      scale: 28
    })
  },
  addWx:function(){
    wx.setClipboardData({
      data: app.globalData.wxID,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log(res.data) // data
            wx.showToast({
              title: '成功复制微信号',
              icon: 'success',
              duration: 2000
            })
          }
        })
      }
    })
  },
  getUserInfo: function (e) {
    //console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    console.log("sex:"+ e.detail.userInfo.gender)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true,
    })
  }
})